#include<iostream>
#include<vector>
#include"tools.h"
#include"employee.h"
#include"department.h"
#include"serviceview_console_impl.h"

void ServiceViewConsoleImpl::menu()
{
	while(1)
	{
		clears();
		cout << "ServiceView" <<endl;
		cout << "1.addDept" << endl;
		cout << "2.deleteDept" << endl;
		cout << "3.addEmp" << endl;
		cout << "4.deleteEmp" << endl;
		cout << "5.modifyEmp" << endl;
		cout << "6.listDept" << endl;
		cout << "7.listEmpt" <<endl;
		cout << "8.listAllEmpt" << endl;
		cout << "9.return"<< endl;
		int num;
		clear_stdin();
		cin >> num;
		switch(num)
		{
			case 1:addDept();break;
			case 2:delDept();break;
			case 3:addEmp();break;
			case 4:delEmp();break;
			case 5:modEmp();break;
			case 6:listDept();break;
			case 7:listEmp();break;
			case 8:listAllEmp();break;
			case 9:return;

		}
	}	
}
bool ServiceViewConsoleImpl::addDept()
{
	clear_stdin();
	Department dept;
	string _n_name;
	cout <<"please input dept name:";
	cin >> _n_name;
	dept.change_name(_n_name);
	int num = get_id("./account/id.dat");
	dept.change_id(num);
	ser->addDept(dept);
	clear_stdin();
	anykey_continue();
	return true;
}
bool ServiceViewConsoleImpl::delDept()
{
	int num;
	cout << "please input Dept id:";
	clear_stdin();
	cin >> num;
	Department dept;
	dept.change_id(num);
	ser->delDept(dept.get_department_id());
	clear_stdin();
	anykey_continue();
	return true;
}
bool ServiceViewConsoleImpl::addEmp()
{
	clear_stdin();
	Employee emp;
	int num;
	cout << "please input Department id:";
	cin >> num;
	string _name;
	cout << "please input name:";
	clear_stdin();
	cin >> _name;
	emp.change_name(_name);
	bool _sex;
	cout << "please input sex(1.m 0.f):";
	clear_stdin();
	cin >> _sex;
	emp.change_sex(_sex);
	int _age;

	cout << "please input age:";
	clear_stdin();
	cin >> _age;
	emp.change_age(_age);
	int count = get_id("./account/id.dat");;
	emp.change_id(count);
	ser->addEmp(num,emp);
	clear_stdin();
	anykey_continue();
	return true;
}
bool ServiceViewConsoleImpl::delEmp()
{
	Employee emp;
	int id;
	cout << "please input Department id:";
	cin >> id;
	cout << "please input delid:";
	int num;
	cin >> num;
	emp.change_id(num);

	ser->delEmp(id,emp.get_employee_id());
	clear_stdin();
	anykey_continue();
	return true;
}
bool ServiceViewConsoleImpl::modEmp()
{
	Employee emp;
	int depid;
	cout << "please input deptid:";
	clear_stdin();
	cin >> depid;
	cout << "please input modmen id:";
	int idd;
	clear_stdin();
	cin >> idd;
	string _name;
	cout << "please input name:";
	clear_stdin();
	cin >> _name;
	emp.change_name(_name);
	bool _sex;
	cout << "please input sex(1.m 0.f):";
	clear_stdin();
	cin >> _sex;
	emp.change_sex(_sex);
	int _age;
    clear_stdin();
	cout << "please input age:";
	clear_stdin();
	cin >> _age;
	emp.change_age(_age);
	emp.change_id(idd);
	ser->modEmp(depid,idd,emp);
	clear_stdin();
	anykey_continue();
	return true;
}
void ServiceViewConsoleImpl::listDept()
{
	ser->listDept();
	clear_stdin();
	anykey_continue();
}
void ServiceViewConsoleImpl::listEmp()
{
	Department dep;
	int num;
	cout << "please input list Departmentid:";
	clear_stdin();
	cin >> num;
	dep.change_id(num);
	ser->listEmp(dep.get_department_id());
	clear_stdin();
	anykey_continue();
}
void ServiceViewConsoleImpl::listAllEmp()
{
	ser->listAllEmp();
	clear_stdin();
	anykey_continue();
}
